#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

long long mostPoints(vector<vector<int>>& q) {
    int n = q.size();
    vector<long long> f(n + 1);
    for (int i = n - 1; i >= 0; i--)
    {
        f[i] = f[i + 1];
        int d = min(n, i + q[i][1] + 1);
        f[i] = max(f[i], f[d] + q[i][0]);
    }
    return f[0];
}

int main()
{
    vector<vector<int>> vv = { {3,2},{4,3},{4,4},{2,5} };
    cout << mostPoints(vv);
	return 0;
}